package db5;

import java.util.Scanner;

public class Student1 {
    private int no;
    private String name;
    private int age;
    private String sex;
    public Student1(){
    }
    public Student1(int no,String name,int age,String sex){
        this.no = no;
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    public  int getNo(){
        return no;
    }
    public void setNo(int no){
        this.no=no;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        this.age=age;
    }
    public String getSex(){
        return sex;
    }
    public void setSex(String sex){
        this.sex=sex;
    }
    public static void selectAll(Student[] students){
//        定义方法  查看所有学生信息
        if (students.length==0){
            System.out.println("没有学生信息");
        }else {
            for (int i = 0; i < students.length; i++) {
                Student student = students[i];
//                System.out.println(i);
                System.out.println("学号；"+student.no+"，姓名；"+student.name+"，年龄；"+student.age+"，性别；"+student.sex);
            }
        }
    }
    public static void selectByName(Student[] students){
        Scanner input = new Scanner(System.in);

//        定义方法   查询学生信息
        System.out.println("请输入要查询的学生信息");
        String name = input.next();

        Student student=null;

        for (int i = 0; i < students.length; i++) {
//            如果查到的和表里的一样，循环停止
            if (name.equals(students[i].name)){
                student=students[i];
                break;
            }
        }
        if (student==null){
//            空就是没查到
            System.out.println("没有此学生");
        }else {
//            查到就输出
            System.out.println("学号；"+student.no+"，姓名；"+student.name+"，年龄；"+student.age+"，性别；"+student.sex);
        }
    }
    static Scanner input = new Scanner(System.in);

    public static void add(Student[] students){
//        1.创建学生对象，现在都是默认值；
        Student student=new Student();
//        2.通过录入器录入学生信息
        System.out.println("请输入编号");
        student.no=input.nextInt();
        //        3.校验是否重复；
        boolean isFind =false;
        for (int i = 0; i <students.length ; i++) {
            if(student.no==students[i].no){
                isFind=true;
                break;
            }

        }

//        判断是否为true
        if (isFind){
            System.out.println("学号重复");
        }else {
            System.out.println("请输入姓名");
            student.name = input.next();
            System.out.println("请输入年龄");
            student.age = input.nextInt();
            System.out.println("请输入性别");
            student.sex = input.next();

//            4.存入数据；地方不够（扩容数组）
            Student[] copy =new Student[students.length+1];
            for (int i = 0; i < students.length; i++) {
                copy[i]=students[i];
            }

            students=copy;

//            5.存入数组
            students[students.length-1] =student;
        }
    }
}
